package ru.amse.baltijsky.javascheme.nodeshape;

import ru.amse.baltijsky.javascheme.util.Size;
import ru.amse.baltijsky.javascheme.util.VisConst;

import java.awt.*;

/**
 * Represents the shape for the action node, which is a box housing the code frame.
 */
public class ActionNodeShape extends AbstractNodeShape {
    /**
     * The offset for the code frame in the shape.
     */
    private final static Size OFFSET = new Size(5, 5);

    /**
     * Creates a new shape for Action node that contains the specified code.
     *
     * @param code the node code
     */
    public ActionNodeShape(String code) {
        super(code);
    }

    public void draw(int x, int y, Graphics g) {
        Size size = getBoundRectSize(g);
        Color oldColor = g.getColor();

        g.setColor(VisConst.SCHEME_COL);
        g.drawRect(x - size.x / 2, y - size.y / 2, size.x, size.y);
        g.setColor(VisConst.TEXT_COL);
        g.drawString(getCode(), x - size.x / 2 + OFFSET.x, y + OFFSET.y);

        g.setColor(oldColor);
    }

    public Size getBoundRectSize(Graphics g) {
        Size codeSize = getCodeSize(g);
        int sizeX = codeSize.x + 2 * OFFSET.x;
        int sizeY = codeSize.y + 2 * OFFSET.y;
        return new Size(sizeX, sizeY);
    }
}
